package br.ufrj.dcc.tp.utils;

import java.util.List;

import br.ufrj.dcc.tp.utils.interfaces.ISocketMessage;

/** Implementacao das mensagens que serao enviadas via TCP/IP. */
public class SocketMessageImpl implements ISocketMessage {
	
	private static final long serialVersionUID = 2L;
	
	/** O remetente da mensagem. */
	private String sender;
	/**Os destinatarios da mensagem. */
	private List<String> recipients;
	/** A mensagem que sera enviada. */
	private Object message;
	/** A acao que a mensagem ira encaminhar.*/
	private SocketAction action;
	
	public SocketMessageImpl() {}
	
	// Usado no handshake
	public SocketMessageImpl(String sender, SocketAction action) {
		this.sender = sender;
		this.action = action;
	}
	
	// Usado no envio de mensagens
	public SocketMessageImpl(String sender, SocketAction action, List<String> recipients, Object message) {
		this(sender, action);
		this.recipients = recipients;
		this.message = message;
	}
	
	// Usado pelo servidor na resposta da listagem.
	public SocketMessageImpl(String sender, SocketAction action, Object message) {
		this(sender, action);
		this.message = message;
	}
	
	@Override
	public Object getBody() {
		return message;
	}

	@Override
	public List<String> getRecipients() {
		return recipients;
	}

	@Override
	public SocketAction getAction() {
		return action;
	}
	
	@Override
	public String toString() {
		return message.toString();
	}

	@Override
	public String getSender() {
		return sender;
	}

	public SocketMessageImpl setSender(String sender) {
		this.sender = sender;
		return this;
	}

	public SocketMessageImpl setRecipients(List<String> recipients) {
		this.recipients = recipients;
		return this;
	}

	public SocketMessageImpl setMessage(Object message) {
		this.message = message;
		return this;
	}

	public SocketMessageImpl setAction(SocketAction action) {
		this.action = action;
		return this;
	}
}
